// https://nuxt.com/docs/api/configuration/nuxt-config
// export default defineNuxtConfig({
//   compatibilityDate: '2025-05-15',
//   devtools: { enabled: true }
// })
// https://nuxt.com/docs/api/configuration/nuxt-config
import { resolve } from 'path'
import { fileURLToPath } from 'url'
export default defineNuxtConfig({
  // spaLoadingTemplate: './app/spa-loading-template.html',
  // spaLoadingTemplate: resolve(__dirname, 'app/spa-loading-template.html'),
  spaLoadingTemplate: resolve(
    fileURLToPath(new URL('.', import.meta.url)),
    './app/spa-loading-template.html'
  ),
  devServer: {
    host: '0.0.0.0', // 允许局域网访问
    port: 3000      // 默认端口
  },
  nitro: {
    compressPublicAssets: true, // 压缩公共资源
    //   publicAssets: [
    //     {
    //       baseURL: '/uploads',
    //       dir: 'public/uploads'
    //     }
    //   ]
  },
  ssr: true, // 必须开启 SSR
  // routeRules: {
  //   // 对静态页面预渲染
  //   '/static-page': { prerender: true },
  //   // 对某些路由关闭SSR
  //   '/client-only': { ssr: false }
  // },
  app: {
    layoutTransition: { name: 'layout', mode: 'out-in' },
    pageTransition: { name: 'page', mode: 'out-in' },
    rootId: 'nuxt-app',       // 确保根容器 ID 明确
    head: {
      charset: 'utf-8',
      viewport: 'width=device-width, initial-scale=1',
      title: '企业官网标题',
      meta: [
        { name: 'description', content: '企业官网描述1' },
        { name: 'keywords', content: '关键词1,关键词2' },
        // Open Graph 协议
        { property: 'og:type', content: 'website' },
        { property: 'og:title', content: '企业官网标题' },
        { property: 'og:description', content: '企业官网描述' },
        { property: 'og:image', content: 'https://你的域名.com/share-image.jpg' },
        // Twitter 卡片
        { name: 'twitter:card', content: 'summary_large_image' }
      ],
      link: [
        // 修正 canonical 配置方式
        { rel: 'canonical', href: 'https://你的域名.com' }
      ],
    }
  },
  // 启用 TypeScript
  typescript: {
    strict: true,
    typeCheck: true
  },
  // 自动导入组件
  // components: {
  //   dirs: [
  //     '~/components',
  //     '~/components/ui'
  //   ]
  // },
  components: [
    { path: '~/components', pathPrefix: false } // 禁用路径前缀
  ],
  css: ['~/assets/css/fonts.css', '~/assets/css/main.css'],
  // tailwindcss: {
  //   configPath: '~/tailwind.config.js'
  // },
  // 模块配置
  modules: [
    '@pinia/nuxt',
    '@nuxtjs/tailwindcss',
    'nuxt-swiper',
  ],
  build: {
    analyze: {
      enabled: true,
      reportFilename: ".nuxt/analyze/report.html"
    },
    transpile: ['three'],
  },
  // Vite 配置 (Nuxt 3 默认使用 Vite)
  vite: {
    optimizeDeps: {
      include: ['three', '@photo-sphere-viewer/core']
    },
    server: {
      fs: {
        strict: false
      }
    },
    build: {
      // @ts-ignore
      plugins: [],
      rollupOptions: {
        output: {
          manualChunks: {
            'vendor-group': ['vue', 'vue-router', 'pinia'],
            'chartjs': ['chart.js'],
            //  'ui-lib': ['naive-ui'],
          }
        }
      }
    },
  },

  // 运行时配置
  runtimeConfig: {
    public: {
      appName: process.env.NUXT_PUBLIC_APP_NAME, // 自动注入
      apiBase: process.env.NUXT_PUBLIC_API_BASE   // 自动注入
    },
    jwtSecret: process.env.JWT_SECRET || 'your-secret-key',
    dbHost: process.env.DB_HOST,
    dbUser: process.env.DB_USER,
    dbPassword: process.env.DB_PASSWORD,
    dbName: process.env.DB_NAME,
    // 私有变量（仅服务端）
    databaseUrl: process.env.DATABASE_URL
  },
  // 根据环境启用不同配置
  devtools: { enabled: process.env.NODE_ENV === 'development' },
  sourcemap: process.env.NODE_ENV !== 'production',

  // 自动导入配置
  imports: {
    dirs: ['stores']
  }
})